<template>
  <div class="photo-info">
    <van-panel
      :title="photocontent.title"
      :status="'阅读' + photocontent.click"
    >
      <div class="imgbox">
        <img
          v-for="(el, index) in imgsbox"
          :key="el.id"
          :src="el.src"
          @click="showpreview(index)"
        />
      </div>
      <div class="conntent">{{ photocontent.content }}</div>
    </van-panel>
    <comment :id="id"></comment>
  </div>
</template>
<script>
import { ImagePreview } from 'vant'
import comment from '@/components/comment'
export default {
  props: ['id'],
  data: () => ({
    photocontent: [],
    imgsbox: []
  }),
  methods: {
    async getImageInfo() {
      const res = await this.$http.getImageInfo(this.id)
      this.photocontent = res.data.message
    },
    async getThumImages() {
      const res = await this.$http.getThumImages(this.id)
      this.imgsbox = res.data.message
    },
    showpreview(startPosition) {
      const images = []
      this.imgsbox.forEach(el => {
        images.push(el.src)
      })
      ImagePreview({
        images,
        startPosition
      })
    }
  },
  created() {
    this.getImageInfo()
    this.getThumImages()
  },
  components: {
    comment
  }
}
</script>
<style lang="scss" scoped>
.photo-info {
  .imgbox {
    display: flex;
    justify-content: space-around;
    padding: 5px 0;
    img {
      width: 100px;
      height: 100px;
    }
  }
  .conntent {
    margin-bottom: 10px;
  }
}
</style>
